#ifndef SLOTCONN_H
#define SLOTCONN_H


#include "progconn.h"
#include "slotguts.h"
#include "slotspin.h"

#ifdef ALLOW_SPIN_TESTING
	#include "SpinTestData.h"
#endif

class XMLTranslator;

class SlotConnection : public ProgressiveConnection
{
	public:
		SlotConnection(ProgressiveServer*server, SOCKET client);
		~SlotConnection();

		void msgStart();
		void msgAdd(uint8 Byte);
		uint8* msgGetBuf();
		void msgReleaseBuf(int32 Amt);
		void msgEnd();
		bool8	getLocale( localCurrency* lc, int32* chipValues, int32 numChipValues );

	protected:
		bool8	getResponse();
		void    allocateXMLTranslator( XMLTranslator** target );

		void	sendStopMsg();
		void	sendMalfunctionMsg();
		void	sendLoginMalfunctionMsg();

		bool8	parseAnsiCasinoLogin(int32 stdReq, int32* Err);
		bool8	parseUnicodeCasinoLogin(int32 stdReq, int32* Err);
		void	removeCasinoSpecific();

		int32	encode(uint8*, uint8*, int32);
		int32	decode(uint8*, uint8*, int32);

		bool8   trackGetBalance();
		bool8	trackGetPlayerLimits();
		int32	trackValidateLogin();
		int32	trackValidateSession();

        bool8 handleGutsMsg();
        bool8 handleGutsReelsMsg();
        bool8 handleGutsPaylinesMsg();
		bool8 handleBonusGameMsg();

        bool8 handleGutsIconNameMsg();
        bool8 handleGutsDenominationsMsg();

        bool8 handleSavedGameMsg();
        bool8 handleJackpotMsg();
		bool8 handleFixedJackpotMsg(int32 JackpotValue);	// CSN-5756: with the new korean team game (Saturn GP) we need to support fixed jackpot amounts
        bool8 handleLoginMsg();

		bool8 handleAnsiLoginMsg();
		bool8 handleUnicodeLoginMsg();

        bool8 handleSubgameMsg();
		bool8 handleClientErrorMsg();

#ifdef ALLOW_SPIN_TESTING
		bool8 handleSpinTestMessage();
		void executeSpinTest( uint32 nNumSpins, uint32 nLines, uint32 nBetPerLine );
#endif

        bool8 handleSpinMsg();

		void executeSpinMsg( uint8 lineCount, bool8 bAutoplay);
        void packSpin();
        bool8 handleClientDataMsg();
        bool8 handleUnknownMsg();
        bool8 handleGetBalance();

        void SendInt32(int32 data);
		void SendInt64(int64 data);
        void SendUint16(uint16 data);
        void SendUint8(uint8 data);
        uint8 SendString( char* s );

		virtual int32 getProgressiveFixedAmountMultiplier();

		void    trackLogoutSession();	// CSN-7075: New Authentication

	protected:
		int32 loggedOn;

		SlotGuts* guts;
		pInfo info;
		int32 msglen;
		uint8 msgbuf[CONNECT_OBUF];

#ifdef ALLOW_SPIN_TESTING
		CSpinTestData m_SpinTestData;
#endif

        //ProgressiveConnection abstract function required to be implemented by subclass
        virtual bool8 getForRealFlag();

	protected:
		int32 creditsToCents(int32 cred);
		int32 centsToCredits(int32 cents);

	// [AO 2008-01-16] Refactoring for HA
	private:
		bool ValidateSession();
};

inline
int32
SlotConnection::getProgressiveFixedAmountMultiplier()
{
	// Auslots don't have a Fixed Amount Multiplier
	return 1;
}

#endif
